package FlowGram.Application.IDEWindow.FileManager;

import java.awt.event.MouseEvent;
import java.util.EventObject;

import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellEditor;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.TreeCellEditor;
import javax.swing.tree.TreePath;


/**
 * 
 * @author thackray
 *
 */
public class WorkspaceTreeCellEditor extends DefaultTreeCellEditor {

	public WorkspaceTreeCellEditor(JTree tree, DefaultTreeCellRenderer renderer) {
		super(tree, renderer);
	}

	@Override  
    public boolean isCellEditable(EventObject event){  
        if(!super.isCellEditable(event)){  
            return false;  
        }  
        if(event != null && event.getSource() instanceof JTree && event instanceof MouseEvent){  
            MouseEvent mouseEvent = (MouseEvent)event;  
            JTree tree = (JTree)event.getSource(); 
            
            TreePath path = tree.getPathForLocation(mouseEvent.getX(), mouseEvent.getY()); 
            DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.getLastPathComponent();
            if(node.getUserObject() instanceof CodeFileItem 
            		|| node.getUserObject() instanceof TerrainFileItem
            		|| node.getUserObject() instanceof ProjectFileItem){
            	return true;
            }
        }  
        return false;  
    }  

}
